package gameserver.model.gameobjects.stats.modifiers;

import java.util.ArrayList;
import java.util.List;

import gameserver.model.gameobjects.stats.StatEnum;
import gameserver.model.gameobjects.stats.StatModifierPriority;

import javax.xml.bind.annotation.*;


@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Modifier")
public abstract class StatModifier implements Comparable<StatModifier>
{
	@XmlAttribute
    private StatEnum name;
	protected static int MODIFIER_ID = 0;

    protected int id;
    
    protected List<StatEnum> statToModifies;
	
    public StatModifier() {
        nextId();
        setStatToModifies(new ArrayList<StatEnum>());
    }

    protected void setStat(StatEnum stat) {
        this.name = stat;
    }


    protected void nextId() {
        MODIFIER_ID = (MODIFIER_ID + 1) % Integer.MAX_VALUE;
        id = MODIFIER_ID;
    }

    public StatEnum getStat() {
        return name;
    }

    @Override
    public int compareTo(StatModifier o) {
        int result = 0;
        if (result == 0) {
            result = id - o.id;
        }
        return result;
    }

    @Override
    public boolean equals(Object o) {
        boolean result = (o != null);
        result = (result) && (o instanceof StatModifier);
        result = (result) && (((StatModifier) o).id == id);
        return result;
    }

    @Override
    public int hashCode() {
        return id;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(this.getClass().getSimpleName() + ",");
        sb.append("i:" + id + ",");
        sb.append("s:" + name);
        return sb.toString();
    }

    public abstract int apply(int baseValue, int currentValue);
    public abstract StatModifierPriority getPriority();

	public List<StatEnum> getStatToModifies()
	{
		return statToModifies;
	}

	public void setStatToModifies(List<StatEnum> statToModifies)
	{
		this.statToModifies = statToModifies;
	}

}
